package com.bristua.mall.user.biz;

import com.bristua.mall.common.utils.CacheUtil;
import com.bristua.mall.user.dao.TUserMapper;
import com.bristua.mall.user.model.TUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by Administrator on 2019/5/12.
 */
@Transactional
@Service
public class FinushUserInfoBiz {

    @Resource
    private TUserMapper tUserMapper;

    @Autowired
    private CacheUtil cacheUtil;

    public void finushUserInfo(Map<String,Object> map){
        TUser userSession = (TUser) cacheUtil.getUserSession();
        Object userImgUrl = map.get("userImgUrl");
        TUser tUser = new TUser();
        tUser.setUserId(userSession.getUserId());
        if(!StringUtils.isEmpty(userImgUrl)){
            tUser.setUserImgUrl(userImgUrl.toString());
        }

        Object nickName = map.get("nickName");
        if(!StringUtils.isEmpty(nickName)){
            tUser.setNickName(nickName.toString());
        }
        tUserMapper.updateByPrimaryKeySelective(tUser);

    }
}
